package me.zk.practice1.hw;

import java.util.*;

/**
 * @author zhangkai
 * @date 2023/8/10 15:42
 */
public class HWBJJ17 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int max = Integer.parseInt(scanner.nextLine());

        int len = Integer.parseInt(scanner.nextLine());

        List<Interview> list = new ArrayList<>();
        for (int i = 0; i < len; i++) {
            int[] nums = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
            Interview v = new Interview(nums[0],nums[1]);
            list.add(v);
        }
        Collections.sort(list);

        List<List<Interview>> offs = new ArrayList<>();

        for (Interview v : list) {

            boolean isOk = true;

            //遍历每个面试官
            for(List<Interview> l : offs) {
                if (l.size() < max) {
                    //判断是否有重叠
                    Interview interview = l.get(l.size()-1);
                    if (interview.end<=v.start) {
                       l.add(v);
                       isOk = false;
                       break;
                    }
                }
            }

            if (isOk) {
                List<Interview> list1 = new ArrayList<>();
                list1.add(v);
                offs.add(list1);
            }

        }
        System.out.println(offs.size());
    }

    static class Interview implements Comparable<Interview> {
        int start;

        int end;

        public Interview(int start, int end) {
            this.start = start;
            this.end = end;
        }

        @Override
        public int compareTo(Interview ot) {
            if (ot.start == this.start) {
                return this.end - ot.end;
            }
            return this.start - ot.start;
        }
    }
}
